#[cfg(test)]
mod test {
    use bytes::Bytes;
    #[test]
    fn buf() {

        let b = Bytes::new();
        assert_eq!(b.len(), 0);
        assert!(b.is_empty());


        //From<&'static [u8]>
        let b = Bytes::from(&[1, 2, 3, 4][..]);
        assert_eq!(b.len(), 4);
        
        //from &[u8]
        let arr = vec![1, 3, 5]; 
        let b = Bytes::copy_from_slice(arr.as_slice());
        assert_eq!(b.len(), 3);

        //from Vec[u8]
        let b = Bytes::from(vec![1, 2, 3, 4, 5]);
        assert_eq!(b.len(), 5);

        // convert Vec<u8> to Bytes
        let v = Vec::<u8>::from(b.clone());
        assert_eq!(v.len(), 5);


        //slice
        let n_bytes = b.slice(2..5);
        assert_eq!(&[3, 4, 5][..], n_bytes);

        
        let subset = b.slice_ref(&b.as_ref()[0..3]); //must be subset of it
        assert_eq!(subset.len(), 3);
        assert_eq!(b.slice(0..3), subset);

        
        let mut buf = Bytes::from(&b"Hello world"[..]);
        buf.truncate(5);
        assert_eq!(buf, b"Hello"[..]);
        
        let left = buf.split_to(1);
        assert_eq!(left, b"H"[..]);
        assert_eq!(buf, b"ello"[..]);

        let right = buf.split_off(2);
        assert_eq!(right, b"lo"[..]);
        assert_eq!(buf, b"el"[..]);

        buf.clear();
        assert!(true == buf.is_empty());
    }
    //use bytes::Buf;
    use bytes::BytesMut;
    use bytes::BufMut;
    #[test]
    fn buf_mut(){
        let mut buf = BytesMut::with_capacity(256);
        assert_eq!(buf.len(), 0);
        buf.put_slice(&b"hello"[..]);
        assert_eq!(buf.len(), 5);

        //split 
        //split_to   self->[0,at)
        //split_off  self->[at, end)
        //
        //remaining-read, -> write - remaining -> read - remaining
    }

    use std::io::{Cursor,Write,Seek, SeekFrom};
    #[test]
    fn cursor() {
        let mut c = Cursor::new(Vec::<u8>::new());
        assert_eq!(c.position(), 0);

        assert_eq!(c.write(&b"hello"[..]).unwrap(), 5);
        assert_eq!(c.stream_position().unwrap(), 5);

        assert_eq!(c.position(), 5);

        assert_eq!(c.seek(SeekFrom::Start(2)).unwrap(), 2);
        assert_eq!(c.position(), 2);
    }
}
